package com.gxa.modules.service.operationsservice.impl;

import com.gxa.common.R;
import com.gxa.modules.mapper.operationsmapper.YttBuildMapper;
import com.gxa.modules.pojo.Build;
import com.gxa.modules.pojo.Room;
import com.gxa.modules.service.operationsservice.LouYuXinXiGuanLiService;
import net.sf.saxon.functions.Count;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.sql.Array;
import java.util.ArrayList;
import java.util.List;

@Service
public class LouYuXinXiGuanLiServiceImpl implements LouYuXinXiGuanLiService {

    @Autowired
    private YttBuildMapper yttBuildMapper;
    R r = new R();
    @Override
    public R selectLouYu(String buildName,int page,int limit) {
        int index = (page-1)*limit;
        List<Build> builds = yttBuildMapper.selectLouYu(buildName,index,limit);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(builds);
        r.setCount(yttBuildMapper.selectLouYuCount(buildName));
        return r;
    }

    @Override
    public R delLouYu(String ids) {
        String[] split = ids.split(",");
        int i = yttBuildMapper.delLouYu(split);
        if (i > 0){
            r.setCode(200);
            r.setMsg("删除成功");
        }else {
            r.setCode(500);
            r.setMsg("删除失败");
        }
        return r;
    }

    @Override
    public R insertLouYu(Build build) {
        int i = yttBuildMapper.insertLouYu(build);
        if (i > 0){
            r.setCode(200);
            r.setMsg("添加成功");
        }else {
            r.setCode(500);
            r.setMsg("添加失败");
        }
        return r;
    }

    @Override
    public R updLouYu(Build build) {
        int i = yttBuildMapper.updLouYu(build);
        if (i > 0){
            r.setCode(200);
            r.setMsg("修改成功");
        }else {
            r.setCode(500);
            r.setMsg("修改失败");
        }
        return r;
    }

    @Override
    public R selectRoomByBuildId(int id) {
        List<Room> rooms = yttBuildMapper.selectRoomByBuildId(id);
        r.setCode(200);
        r.setMsg("查询成功");
        r.setData(rooms);
        return r;
    }

    @Override
    public R insertRoom(Room room) {
        int i = yttBuildMapper.insertRoom(room);
        if (i > 0){
            r.setCode(200);
            r.setMsg("添加成功");
        }else {
            r.setCode(500);
            r.setMsg("添加失败");
        }
        return r;
    }
}
